/*
 * @Author: C.
 * @Date: 2023-01-31 16:53:07
 */
/*
 * @Author: C.
 * @Date: 2023-01-31 16:53:07
 */
import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/auth/login',
  Logout = '/auth/logout',
  GetUserInfo = '/user_data/myself',
  GetPermCode = '/getPermCode',
  TestRetry = '/testRetry',
  UpdatePassword = '/user_data/update_password',
  ResetPassword = 'user_data/reset_pwd',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}
export function updatePassword(params: { NewPassword: string; OldPassword: string }) {
  return defHttp.post({ url: Api.UpdatePassword, params });
}
// ResetPassword
export function resetPassword(params) {
  return defHttp.post({ url: Api.ResetPassword, params });
}
export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}

export function testRetry() {
  return defHttp.get(
    { url: Api.TestRetry },
    {
      retryRequest: {
        isOpenRetry: true,
        count: 5,
        waitTime: 1000,
      },
    },
  );
}
